package cn.dancepeak.system.controller;

import cn.dancepeak.dto.LoginDto;
import cn.dancepeak.exception.BusinessException;
import cn.dancepeak.system.service.ILoginServiceImpl;
import cn.dancepeak.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/login")
@Slf4j
public class LoginController {
    @Autowired
    private ILoginServiceImpl loginService;

    //查询
    @PostMapping("/account")
    public R<String> get(@RequestBody LoginDto loginDto){
        try {
            String jwtToken = loginService.get(loginDto);
            return R.ok("登录成功！",jwtToken);
        } catch (BusinessException e) {
            log.info("查询用户异常：{}",e.getMessage());
            return R.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.info("查询系统异常：{}",e.getMessage());
            return R.fail(e.getMessage());
        }
    }
}
